<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/5/4
  Time: 17:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.DB_Airline" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <title>航线管理系统</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }
        table th, table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        table tr:nth-child(even) {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<h2>航空公司列表</h2>
<!-- 查询表单 -->
<form action="index.jsp" method="get">
    <select name="conditionColumn">
        <option value="aid">航空公司ID</option>
        <option value="fid">航班ID</option>
        <option value="date">日期</option>
        <option value="position">位置</option>
        <option value="remain">剩余票数</option>
    </select>
    <input type="text" name="conditionValue" placeholder="输入查询值">
    <input type="submit" value="查询">
</form>
<!-- 显示航空公司列表 -->
<table>
    <thead>
    <tr>
        <th>航线ID</th>
        <th>航班ID</th>
        <th>日期</th>
        <th>位置</th>
        <th>剩余票数</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <%
        DB_Airline dbAirline = new DB_Airline();
        String conditionColumn = request.getParameter("conditionColumn");
        if (conditionColumn == null) {
            conditionColumn = "";
        }
        String conditionValue = request.getParameter("conditionValue");
        if (conditionValue == null) {
            conditionValue = "";
        }
        List<String> returnList = new ArrayList<>();
        dbAirline.find(conditionColumn, conditionValue, returnList);
        for (int i = 0; i < returnList.size(); i += 5) {
    %>
    <tr>
        <td><%= returnList.get(i) %></td>
        <td><%= returnList.get(i + 1) %></td>
        <td><%= returnList.get(i + 2) %></td>
        <td><%= returnList.get(i + 3) %></td>
        <td><%= returnList.get(i + 4) %></td>
        <td>
            <a href="editAirline.jsp?aid=<%= returnList.get(i) %>">编辑</a>
            <a href="deleteAirline.jsp?aid=<%= returnList.get(i) %>">删除</a>
        </td>
    </tr>
    <% } %>
    </tbody>
</table>
<!-- 添加航空公司表单 -->
<h2>添加航线</h2>
<form action="addAirline.jsp" method="post">
    <label for="fid">航班ID:</label>
    <select id="fid" name="fid" required>
        <%
            List<String> fidList = dbAirline.getFlightIds();
            for (String fid : fidList) {
        %>
        <option value="<%= fid %>"><%= fid %></option>
        <% } %>
    </select><br>
    <label for="dateYear">日期 - 年:</label>
    <select id="dateYear" name="dateYear">
        <% for (int year = 2024; year <= 2030; year++) { %>
        <option value="<%= year %>"><%= year %></option>
        <% } %>
    </select>
    <label for="dateMonth">月:</label>
    <select id="dateMonth" name="dateMonth">
        <% for (int month = 1; month <= 12; month++) { %>
        <option value="<%= String.format("%02d", month) %>"><%= String.format("%02d", month) %></option>
        <% } %>
    </select>
    <label for="dateDay">日:</label>
    <select id="dateDay" name="dateDay">
        <% for (int day = 1; day <= 31; day++) { %>
        <option value="<%= String.format("%02d", day) %>"><%= String.format("%02d", day) %></option>
        <% } %>
    </select><br>
    <label for="position">位置:</label>
    <input type="text" id="position" name="position" required><br>
    <label for="remain">剩余票数:</label>
    <input type="number" id="remain" name="remain" required><br>
    <input type="submit" value="添加航线">
</form>
</body>
</html>